package com.job.yingying;

import java.util.Stack;

/**
 * @ClassName: Deme
 * @Description:
 * @Author: 12071
 * @Date: 2022/5/16 17:46
 */
public class YingYing {

    public static void main(String[] args) {

    }

    class TreeNode//节点结构
    {
        int value;
        TreeNode left;
        TreeNode right;
        TreeNode(int value)
        {
            this.value = value;
        }
    }
    //递归方法
    public static void preOrderR(TreeNode biTree)
    {
        //写代码
        if(biTree == null) {
            return;
        }
        System.out.println(biTree);
        preOrderR(biTree.left);
        preOrderR(biTree.right);

    }

    //非递归方法
    public static void preOrder(TreeNode biTree)
    {
        //写代码
        Stack<TreeNode> stack = new Stack<>();
        stack.push(biTree);
        while(!stack.isEmpty()){
            TreeNode node = stack.pop();
            if(node.right!=null) stack.push(node.right);
            if(node.left!=null) stack.push(node.left);
            System.out.println(node.value);
        }
    }
}
